﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using ElementumForever.Interfaces;
using Microsoft.Xna.Framework.Graphics;
using ElementumForever.Factory;
using Microsoft.Xna.Framework;
using ElementumForever.Utility;
using ThirdPartyNinjas.XnaUtility;

namespace ElementumForever.Decorators
{
    abstract class BaseUIDecorator : BaseDecorator, IMouseControl
    {
       protected Vector2 topLeft, topRight, downLeft, downRight, center;
  
        bool select = false;

        public bool IsSelect
        {
            get
            {
                return select;
            }
            set
            {
                select = value;
            }
        }

        public BaseUIDecorator(BaseEntity master) : base(master) { }

        public override void OnCreat()
        {
            base.OnCreat();
            topLeft = new Vector2();
            topRight = new Vector2();
            downLeft = new Vector2();
            downRight = new Vector2();
            center = new Vector2();
        }

        public virtual void OnMouseClick(MouseState state) {
            Vector2 mp = UnitHelper.ToVector2(state.X, state.Y);
            BaseEntity entity = _component.Parent.PickChildren(mp);
            IsSelect = (entity == _component);
        }

        public virtual void OnMouseDown(MouseState state) { }

        public virtual void OnMouseUp(MouseState state) { }

        public virtual void OnMouseMove(MouseState state) { }

        public override void OnUpdate(GameTime gameTime)
        {
            base.OnUpdate(gameTime);

            if (_component != null)
            {
                Vector2 _center = new Vector2(OriginX, OriginY); ;
                Vector2 baseTopLeft = _center - new Vector2(OriginX,OriginY);
                topLeft = baseTopLeft;
                topRight = baseTopLeft + new Vector2(Width, 0);
                downLeft = baseTopLeft + new Vector2(0, Height);
                downRight = baseTopLeft + new Vector2(Width, Height);
                center = _center;
            }
        }

        protected override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {}
    }
}
